<?php

namespace App\Transformers\Frontend;

use App\Models\Customer\Customer;
use League\Fractal\TransformerAbstract;

class CustomerTransformer extends TransformerAbstract
{

    protected $availableIncludes = ['info'];

    protected $hidden = ['id', 'openid', 'password'];

    public function transform(Customer $model)
    {
        $model->makeHidden($this->hidden);
        return $model->attributesToArray();
    }

    public function includeInfo(Customer $model)
    {
        $info = $model->info;
        if (!$info) {
            return $this->null();
        }
        return $this->item($info, new CustomerInfoTransformer());
    }
}